package com.itheima.d5_resource;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：掌握释放资源的方式。
 */
public class Test2 {
    public static void main(String[] args)  {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D:\\学习\\毕业设计\\备份\\初稿_王鹏飞_毕业设计1-7.pdf");
            fos = new FileOutputStream("哈哈.pdf");

            int len;
            byte[] bytes = new byte[4096];

            while((len = fis.read(bytes)) != -1){
                fos.write(bytes,0,len);
            }
        } catch (Exception e)   {
            e.printStackTrace();
        }finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if(fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }
    }
}
